/******************************************************************************
 * Copyright (C) 2025 Engineer Liu Si 
 * 
 * All Rights Reserved.
 * 
 * @file bsp_key_irq.c
 * 
 * @par dependencies 
 * - stdio.h
 * - stdint.h
 * 
 * @author liusi
 * 
 * @brief Provide the HAL APIs of Key and corresponding opetions.
 * 
 * Processing flow:
 * 
 * call directly.
 * 
 * @version V1.0 2025-09-27
 *
 * @note 1 tab == 4 spaces!
 * 
 *****************************************************************************/
 
#ifndef _BSP_KEY_IRQ_H_
#define _BSP_KEY_IRQ_H_

//******************************** Includes *********************************//

#include <stdint.h>              // the compiling       
#include <stdio.h>

#include "main.h"                // Core / OS layer
#include "cmsis_os.h"
#include "queue.h"

//******************************** Includes *********************************//

//******************************** Defines **********************************//
#define OS_SUPPORTING 

//******************** Thread_Func ***********************//
extern osThreadId_t key_TaskHandle;
extern const osThreadAttr_t key_Task_attributes;
//******************** Thread_Func ***********************//


//******************* Queue_Handler **********************//
extern QueueHandle_t key_queue;
extern QueueHandle_t key_queue_irq;

//******************* Queue_Handler **********************//

typedef enum
{
  KEY_OK                = 0,           /* Operation completed successfully.  */
  KEY_ERROR             = 1,           /* Run-time error without case matched*/
  KEY_ERRORTIMEOUT      = 2,           /* Operation failed with timeout      */
  KEY_ERRORRESOURCE     = 3,           /* Resource not available.            */
  KEY_ERRORPARAMETER    = 4,           /* Parameter error.                   */
  KEY_ERRORNOMEMORY     = 5,           /* Out of memory.                     */
  KEY_ERRORISR          = 6,           /* Not allowed in ISR context         */
  KEY_RESERVED          = 0x7FFFFFFF   /* Reserved                           */
} key_status_t;


typedef enum
{
  KEY_PRESSED                = 0,      /* Key is  Pressed                    */
  KEY_LONG_PRESSED           = 1,      /* Key is  Long Pressed               */
  KEY_NOT_PRESSED            = 2,      /* Key not Pressed                    */
  KEY_TWO_PRESSED            = 3,      /* Key is  Contiue Two Pressed        */
  KEY_THREE_PRESSED          = 4,      /* Key is  Contiue Three Pressed      */
  KEY_FOUR_PRESSED           = 5,      /* Key is  Contiue Four Pressed       */
} key_press_status_t;

typedef enum
{
  KEY_FALLING                = 0,      /* Key is  Pressed                    */
  KEY_RISEING                = 1,      /* Key is  Long Pressed               */
  KEY_ERR_STATE              = 0xFF,   /* Key is  error state                */
} key_edag_status_t;

typedef struct bsp_key_tx
{
  key_edag_status_t  key_press_status; /* Key Press state                    */
  uint32_t               sys_tick_cnt; /* Key pressing timetick              */
}key_tx_message_t;
//******************************** Defines **********************************//

//******************************** Declaring ********************************//
/**
 * @brief Instantiates the bsp_led_handler_t target.
 * 
 * Steps:
 *  1.doing the specific operations.
 *  
 * 
 * @param[in] void
 * @return led_handler_status_t : Status of the function.
 * 
 * */
key_status_t key_scan( key_press_status_t * key_value );

/**
 * @brief Key_Task_Func for thread to run.
 * 
 * Steps:
 *  1.doing the specific operations.
 *  
 * 
 * @param[in] void
 * @return led_handler_status_t : Status of the function.
 * 
 * */
void         Key_Task_Func             (void *argument);

//******************************** Declaring ********************************//
 

 
#endif //End of _BSP_KEY_H_
